/*
 *  rgb.h
 *  Ray Tracer
 *  Functions and struct to represent RGB floating point values.
 *
 *  Created by Chirantan Ekbote on 9/7/10.
 *  Copyright 2010 Ohio State University. All rights reserved.
 *
 */

#ifndef _RGB_H_
#define _RGB_H_

#ifdef  __cplusplus
extern "C" {
#endif	// __cplusplus
	
#include "vec3.h"
	
typedef struct rgb {
	float r;
	float g;
	float b;
} rgb;

static inline rgb makeRGB(const float r, const float g, const float b) {
	rgb temp = {r, g, b};
	return temp;
}

static inline rgb makeRGBvec3(const vec3 v) {
	rgb temp = {v.x, v.y, v.z};
	return temp;
}
	
static inline rgb rgbAdd(const rgb c1, const rgb c2) {
	rgb temp = {c1.r + c2.r, c1.g + c2.g, c1.b + c2.b};
	return temp;
}

static inline rgb rgbMul(const rgb c1, const rgb c2) {
	rgb temp = {c1.r * c2.r, c1.g * c2.g, c1.b * c2.b};
	return temp;
}

static inline rgb rgbScalarMul(const rgb c, const float f) {
	rgb temp = {c.r * f, c.g * f, c.b * f};
	return temp;
}

static inline rgb rgbDiv(const rgb c1, const rgb c2) {
	rgb temp = {c1.r / c2.r, c1.g / c2.g, c1.b / c2.b};
	return temp;
}

static inline rgb rgbScalarDiv(const rgb c, const float f) {
	float div = 1.0f / f;
	rgb temp = {c.r * div, c.g * div, c.b * div};
	return temp;
}

static inline void rgbClamp(rgb c) {
	if (c.r > 1.0f) { c.r = 1.0f; }
	if (c.g > 1.0f) { c.g = 1.0f; }
	if (c.b > 1.0f) { c.b = 1.0f; }
	
	if (c.r < 0.0f) { c.r = 0.0f; }
	if (c.g < 0.0f) { c.g = 0.0f; }
	if (c.b < 0.0f) { c.b = 0.0f; }
}

static inline rgb rgbNeg(const rgb c) {
	rgb temp  = {-c.r, -c.g, -c.b};
	return temp;
}

#ifdef  __cplusplus
}
#endif	// __cplusplus
#endif // _RGB_H_